package xhwl.insurance.ui;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;

import java.util.ArrayList;

import xhwl.android.common.log.XHLog;
import xhwl.insurance.BaseActivity;
import xhwl.insurance.Constant;
import xhwl.insurance.R;
import xhwl.insurance.adapter.VersionUpdateAdapter;
import xhwl.insurance.http.api.VersionUpdateApi;
import xhwl.insurance.http.bean.resp.VersionUpdateListResp;
import xhwl.retrofitrx.HttpException;
import xhwl.retrofitrx.HttpManager;
import xhwl.retrofitrx.OnNextListener;

/**
 * Created by Administrator on 2017/8/24.
 * 版本功能更新的详情
 */

public class VersionFunctionActivity extends BaseActivity {

    private ListView mListView;
    ArrayList<VersionUpdateListResp> mList = new ArrayList<>();
    private VersionUpdateAdapter adapter;
    private LinearLayout emptyView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.version_function_activity);
    }


    @Override
    public void initViews() {
        initTitleViews();
        mListView = (ListView) findViewById(R.id.lv_version_listview);
        emptyView = (LinearLayout) findViewById(R.id.ll_emptyView);


    }

    @Override
    public void initListener() {


    }

    @Override
    protected void setUpTitleView() {
        titleTextView.setText("功能介绍");
    }

    @Override
    public void loadData() {
        getLoad(1);

    }

    public void getLoad(int page) {
        VersionUpdateApi api = new VersionUpdateApi(Constant.CLIENT_TYPE, page);
        HttpManager.getInstance().dealHttp(this, api, new OnNextListener<ArrayList<VersionUpdateListResp>>() {
            @Override
            public void onNext(ArrayList<VersionUpdateListResp> resp) {
                try {
                    if (null != resp && 0 < resp.size()) {
                        mList.addAll(resp);
                        adapter.notifyDataSetChanged();
                    }else {
                        emptyView.setVisibility(View.VISIBLE);
                    }
                } catch (Exception e) {
                    // TODO: handle exception
                    XHLog.e(e.getMessage());

                }
            }

            @Override
            public void onError(HttpException ex) {
                super.onError(ex);

            }
        });
    }


    @Override
    protected void processOper() {
        adapter = new VersionUpdateAdapter(mContext, mList);
        mListView.setAdapter(adapter);
    }
}
